﻿#ifndef IMAGEVIEWER_H
#define IMAGEVIEWER_H

#include <QGraphicsPixmapItem>
#include <QGraphicsView>
#include <QVariantAnimation>

class ImageViewer : public QGraphicsView
{
    Q_OBJECT
public:
    explicit ImageViewer(QWidget *parent = nullptr);
    ~ImageViewer();

    QString getLastErrorInfo();

    bool loadImage(const QString &filepath="test.png");

protected:
    void wheelEvent(QWheelEvent *e);
    void resizeEvent(QResizeEvent *e);
    void enterEvent(QEvent *e);
    void leaveEvent(QEvent *e);

signals:

private slots:
    void slot_animValueChange(const QVariant &value);

private:
    void bindSignSlot();
    float ratio();
    void zoom(float factor);
    float m11();

    int error_no;

    float zoom_total = 1.0; // 图片的缩放倍率
    QPoint zoom_origin; // 滚动开始时的视图锚点
    QPointF zoom_scene_origin; // 滚动开始时的场景锚点
    QGraphicsPixmapItem *pixmap_item; // 图片项目

    QVariantAnimation zoom_anim; // 缩放动画

    QGraphicsScene *scene;

};

#endif // IMAGEVIEWER_H
